<?php
	require_once '../../defines.php';
	require_once '../../includes/header.php';
	
	if(isLoggedIn()){
		echo "<div><div align='left'><a href='../../main.php'>Main</a></div><div align='right'><a href='../../Login/logout.php'>Logout</a></div></div>";
		echo "<h1>Bugs</h1>";
		echo "<div align='center'><a href='addbug.php'>Add A Bug</a></div>";
		require_once '../../DB/connect.php';
		$bugs = mysql_query("SELECT * FROM bugs ORDER BY resolved");
		$output = "<form method='POST' action='editBug.php'>
		<table cellspacing='5' align='center' border=1>
		<tr><th>Edit</th><th>Title</th><th>Description</th><th>Affected Files</th><th>Creator</th><th>TimeStamp</th><th>Resolved?</th></tr>";
		if(mysql_num_rows($bugs) > 0){
			while($bug = mysql_fetch_array($bugs)){
				$resolved = "No";
				if($bug["resolved"] == 1)
					$resolved = "Yes";
				$output .= '<tr><td><a href="editbug.php?id='.$bug['id'].'">'.$bug['id'].'</a></td>';
				$output .= '<td>'.$bug["title"].'</td><td>'.$bug["description"].'</td><td>'.$bug["files"].'</td><td>'.$bug["username"].'</td><td>'.$bug["datetime"]."</td><td>".$resolved.'</td></tr>';
			}
		}
		$output .= '</table></form>';
		echo $output;
	}
	else{
		echo "<h1>You must be logged in to view this!  Redirecting to Login page...</h1>";
		header("Location: http://".HOST."/DevManagement/Login/login.php");
	}
	
	require_once '../../includes/footer.php';
?>